Learn how to customize the features and design of InstantSearch results page in Algolia extension for Magento 2.
vendor/algolia/algoliasearch-magento-2/view/frontend
folder, which contains the templates, JavaScript, and style sheets in use.
searchBox
stats
sortBy
currentRefinements
queryRuleCustomData
infiniteHits
or hits
pagination
rangeInput
refinementList
rangeSlider
beforeWidgetInitialization
event provided by the extension.
allWidgetConfiguration
parameter has access to the set variable allWidgetConfiguration
. This variable has all the InstantSearch widget configurations already created for you based on your extension settings. Using this event, you can return a modified allWidgetConfiguration
for InstantSearch to render.
The following sections reviews key implementation concepts to help better understand what events to target when customising InstantSearch.
algoliaConfig
global in your developer tools console to review the configurations for the implementation using algoliaConfig.facets
in your store front.
hits
and infiniteHits
widgets display the product results from a search. The extension can configure either options. You can enable infiniteHits
in Stores > Configuration > Algolia Search > InstantSearch Results Page > Enable Infinite Scrolling?
Both widgets use the same template to render the item template: view/frontend/templates/instant/hit.phtml
. To change the rendering of the product result, remember to copy and change the template in your theme instead of directly in the extension
If you need to add complex display conditions to your product hits, use the beforeWidgetInitialization
event hook to transform the hit before passing in the variable to the template.
These widgets have the option to transformItems
, which accepts a callback function. As the extension already utilizes this parameter, make sure that you run the already created function before yours. For example:
{{{exampleNewVariable}}}
Leverage the beforeWidgetInitialization
frontend hook to add more complex logic for your product listing.
beforeInstantsearchInit(instantsearchOptions, algoliaBundle)
instantsearch
optionsbeforeWidgetInitialization(allWidgetConfiguration, algoliaBundle)
beforeInstantsearchStart(search, algoliaBundle)
instantsearch
instance before call of start()
methodafterInstantsearchStart(search, algoliaBundle)
instantsearch
instance after call of start()
methodbeforeInstantsearchInit
Use this event to change the instantsearchOptions
option which accepts a callback function. As the extension already utilizes this parameter, make sure that you run the already created function before yours. For example:
searchParameters
for your search request depends on your extension version. In version 1.x, change this parameter in search options. In versions 2.x and higher, the configure
widget sets the search parameters. This widget accepts an object of searchParameters
. For example:
configure
widget for you, use beforeWidgetInitialization
to make any changes to it. The example below shows how to change and add preconfigured values using the event hook:
toggleRefinement
widget to the InstantSearch page:
templates
directory, and locate the wrapper.phtml
file.
This file is a standard Magento template file.
instant
folder of the templates
directory.
Here are the files used to render the configured widgets:
hit.phtml
- The template for a single productfacet.phtml
- The template for a single filter/facetrefinements.phtml
- The template for current refinementsstats.phtml
- The template for search statistics